/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.nhncorp.neptune.tabletserver;

import java.io.DataOutputStream;
import java.io.IOException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.nhncorp.neptune.common.conf.NConfiguration;
import com.nhncorp.neptune.fs.ChangeLogFileSystem;
import com.nhncorp.neptune.fs.GPath;
import com.nhncorp.neptune.fs.NeptuneFileSystem;
import com.nhncorp.neptune.tablet.TabletInfo;

public class ChangeLogWriter {
  public static final Log LOG = LogFactory.getLog(ChangeLogWriter.class.getName());
  
	//protected DataOutputStream changeLogOut;
  protected GPath changeLogPath;
  protected NConfiguration conf;
  protected NeptuneFileSystem fs;
  protected ChangeLogFileSystem changeLogFileSystem;
  protected TabletInfo tabletInfo;
  
  public ChangeLogWriter(NConfiguration conf, 
      ChangeLogFileSystem changeLogFileSystem, 
      TabletInfo tabletInfo) throws IOException {
    this.tabletInfo = tabletInfo;
    this.changeLogFileSystem = changeLogFileSystem;
	}

//  public void open() throws IOException {
//    Exception exception = null;
//    int retry = 0;
//    while(true) {
//      try {
//        changeLogOut = new DataOutputStream(changeLogFileSystem.open(tabletInfo.getTabletName(), true));
//        return;
//      } catch (Exception e) {
//        exception = e;
//      }
//      try {
//        Thread.sleep(50);
//      } catch (InterruptedException e) {
//      }
//      retry++;
//      if(retry >= 5) {
//        break;
//      }
//    }
//    if(exception == null) {
//      throw new IOException("fail open chagnelog writer: Timeout");
//    }  else {
//      throw new IOException("fail open chagnelog writer:" + exception.getMessage());
//    }
//  }
  
//	public void write(ChangeLog log) throws IOException {
//    if(changeLogOut != null) {
//      log.write(changeLogOut);
//    } else {
//      throw new IOException("Change log stream is closed");
//    }
//	}

//	public void close() throws IOException {
//    changeLogFileSystem.close(changeLogOut);
//	}

//  public void delete() throws IOException {
//    changeLogFileSystem.delete(tabletInfo.getTabletName());
//  }
}
 